ssh -i key.pub でssh-agentで参照する鍵を指定し、Too many authentication failures を回避する
以下のサイトに、ssh実行時にssh-agentでのpubkey authが6回以上になると Too many authentication failures が発生して認証に失敗する対策が書かれていた。
https://developer.1password.com/docs/ssh/agent/advanced/#ssh-server-six-key-limit
結論
.ssh/config の IdentityFileにpublic keyを指定して、 IdentitiesOnly yes にすればOK!
これで ssh: Too many authentication failures を回避できる!
code:config
Host example.com
IdentityFile /path/to/.ssh/id_example.pub
IdentitiesOnly yes
or
code:console
ssh -i ~/.ssh/id_example.pub -o IdentitiesOnly=yes example.com
.pub 指定の仕様
本家ドキュメント
ssh(1) - OpenBSD manual pages
-i : Selects a file from which the identity (private key) for public key authentication is read. You can also specify a public key file to use the corresponding private key that is loaded in ssh-agent(1) when the private key file is not present locally.
公開鍵認証に使用する ID (秘密鍵) を読み込むファイルを選択します。また、公開鍵ファイルを指定すると、秘密鍵ファイルがローカルに存在しない場合に、 ssh-agent(1) で読み込まれる対応する秘密鍵を使用することができます。
参考
SSH client compatibility | 1Password Developer Documentation
各sshクライアントの対応状況
応用事例
@torufurukawa - 午後7:53 · 2022年8月27日
“ssh -i hoge git@github
しても、~/.ssh/id_rsa を使われるんすけど。-v オプションでログをざっと見ると途中で id_rsa 使うわー的に読める。ちゃんとログ読めよとは思いつつ
ssh-agent
が動いてると、hoge 使ってアクセスする。なんなの。”
-i で秘密鍵を指定しても、ssh-agentに登録されている全部の鍵を試行しちゃっているぽい。
対策として -iで公開鍵を指定する
@shimizukawa - 午後9:04 · 2022年8月27日
“ssh -i hoge.pub -o IdentitiesOnly=yes git@github.com
でどうか?”